package com.oms.app.shop.service.impl;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import com.oms.app.sequence.service.impl.SequenceManager;
import com.oms.app.shop.dao.IShopDAO;
import com.oms.app.shop.model.Shop;
import com.oms.app.shop.model.ShopMy;
import com.oms.app.shop.service.IShopService;
import com.oms.core.model.Query;
import com.oms.core.service.impl.GeneralService;
import com.oms.util.DateUtil;
import com.oms.util.QueryUtil;

/**
 * @author Loong_Mit
 * @date Sep 1, 2012 7:03:38 PM
 */

public class ShopServiceImpl extends GeneralService<Shop, String> implements IShopService {

	@Override
	public List<Shop> getShopList(HttpServletRequest request) {
		Query query = QueryUtil.toQuery(request);
		return ((IShopDAO) dao).getShopList(query);
	}
	
	@Override
	public List<Shop> getMyApplyList(String creator) {
		return ((IShopDAO) dao).getMyApplyList(creator);
	}

	@Override
	public int addShop(Shop shopForm) {
		//生成主键ID
		Integer shopId = new Integer(SequenceManager.nextID("shop"));
		shopForm.setId(shopId);
		shopForm.setCreatertime(DateUtil.toDate(DateUtil.getCurrentFullString()));
		return ((IShopDAO) dao).addShop(shopForm) ? shopId : -1;
	}

	@Override
	public boolean deleteShop(String PK) {
		return ((IShopDAO) dao).deleteShop(PK);
	}

	@Override
	public boolean updateShop(Shop shopForm) {
		return ((IShopDAO) dao).updateShop(shopForm);
	}
	
	@Override
	public boolean isOrderFood(String PK) {
		return ((IShopDAO) dao).isOrderFood(PK);
	}
	
	@Override
	public boolean changeShopStatus(String PK, String status) {
		return ((IShopDAO) dao).changeShopStatus(PK, status);
	}

	@Override
	public List<Map<String, Object>> getShopList(Map<String, Object> m) {
		return ((IShopDAO) dao).getShopList(m);
	}
	
	@Override
	public List<Map<String, Object>> getMyShopList(Map<String, Object> m) {
		return ((IShopDAO) dao).getMyShopList(m);
	}
	
	@Override
	public List<Map<String, Object>> getMyOrderList(Map<String, Object> map) {
		return ((IShopDAO) dao).getMyOrderList(map);
	}
	
	@Override
	public List<Map<String, Object>> getMyOrderDetailList(Map<String, Object> map) {
		return ((IShopDAO) dao).getMyOrderDetailList(map);
	}
	
	@Override
	public boolean changeOrderDetailStatus(String key, String status) {
		return ((IShopDAO) dao).changeOrderDetailStatus(key, status);
	}
	 
	@Override
	public boolean deleteOrderDetails(String keyIds) {
		 return ((IShopDAO) dao).deleteOrderDetails(keyIds);
	}
	
	@Override
	public boolean saveApplyShop(ShopMy shopMy) {
		if (shopMy.getUsid() != null && shopMy.getShopid() != null) {
			shopMy.setId(Long.valueOf(SequenceManager.nextID("shop_my")));
			return ((IShopDAO) dao).saveApplyShop(shopMy);
		}
		return false;
	}

	@Override
	public List<Map<String, Object>> getApplyUserList(String shopid) {
		return ((IShopDAO) dao).getApplyUserList(shopid);
	}
	
	@Override
	public boolean isAppliedShop(Long shopId, Long usId) {
		if (shopId != null && usId != null) {
			return ((IShopDAO) dao).isAppliedShop(shopId, usId);
		}
		return true;
	}
}